//
// Created by DengLibin on 2019/1/18 0018.
//
#include <iostream>
#include <vector>
using  namespace std;

/**
 * 柱状图中最大的矩形
 * @param heights
 * @return
 */

int max_68(int x, int y){
    return x > y ? x : y;
}

int largestRectangleArea(vector<int>& heights) {
    int sum = 0, //最大面积
    sum_i = 0,  //每个柱子对应的矩形面积
    len = heights.size(); //数组长度
    int x = 0, y = 0; //下标
    for(int i = 0; i < len; i++){
        //往左边找
        for(x = i; x >= 0; x--){
            if(heights[x] < heights[i]){
                break;
            }
        }
        x = x+1;
        //往右边找
        for(y = i; y < len; y++){
            if(heights[y] < heights[i]){
                break;
            }
        }
        y = y-1;
        //求面积
        sum_i = heights[i] * (y-x+1);
        //取最大值
        sum = max_68(sum_i, sum);
    }
    return sum;
}

int main68(){
    vector<int > v;
    v.push_back(2);
    v.push_back(1);
    v.push_back(5);
    v.push_back(6);
    v.push_back(2);
    v.push_back(3);
    cout << largestRectangleArea(v);
    return 0;
}

